/*
* Authors: Karymov Anton
*          Skorodumov Kirill
* June-August,	2011
*/

#define BOOST_GRAPH_READ_GRAPHVIZ_ITERATORS
#include <boost/graph/graphviz.hpp>
#include <boost/regex.hpp> 
#include "types.h"
#include "branching_algorythm.h"
#include "performance_test.h"
#include <list>
#include "graph_reader.h"
#include "max_degree_algorythm.h"

using namespace boost;
using namespace std;

void main()
{

  char input;
  string fname;
  cout << "Choose what do you want to do:" << endl;
  cout << "1.To start performance test type 'p';" << endl;
  cout << "2.To run max degree algorythm type 'm';" << endl;
  cout << "3.To run optimized branching algorythm type 'o';" << endl;
  cout << "4.To exit enter 'e';" << endl;

  cin >> input;

  switch (input) {
  case 'o':
    {
      cout << "Enter file name ";
      cin >> fname;

      list<vertex_t> cover;		
      graph_t graph = read_graph(fname);
      branching_algorythm Branching_solver(graph);
      Branching_solver.set_optimization_level(1);

      int k;
      cout << "Enter k ";
      cin >> k;

      bool res = Branching_solver.solve(k);

      if (res) {
        cout << "Graph was successfully covered. " << endl;
        std::fstream ofile;
	      ofile.open("output.dot",std::ios::out);
        write_graphviz(ofile, graph, make_label_writer(Branching_solver.get_name_map()));
      } else {
        cout << "Imposible to cover graph with this number of vertices, try to enter larger k" << endl;
      }
      break;
    }
  case 'p':
    {
      int k;
      cout << "Enter k ";
      cin >> k;
      performance_test(k);
      std::cout << "Successfully written output to 'test_log.txt'." << std::endl;
      break;
    }
  case 'm':
    {
      cout << "Enter file name ";
      cin >> fname;
      list<vertex_t> cover;		
      graph_t graph = read_graph(fname);
      max_degree_algorythm Max_degree_solver(graph);
      Max_degree_solver.greedy_min_vertex_cover();
      cover = Max_degree_solver.get_cover();
      cout << "Graph was successfully covered: " << endl;
      for (list<vertex_t>::const_iterator j = cover.begin(); j != cover.end(); ++j) {
        cout << *j << " ";
      }
      break;
    }
  case 'e':
    {
      return;
    }
  default:
    cout << "Wrong input!";
  }
  cin.get();
  cin.get();
}